package biz.ws;

import api.common.Global;
import api.common.util.DubboUtils;
import biz.ws.ws.*;
import biz.ws.ws.sender.KafkaSharedMsgSender;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
import java.util.TimeZone;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * @创建人 wsdc
 * @时间 2021/4/1
 * @描述 $
 */
@SpringBootApplication
@EnableDubbo
@EnableDiscoveryClient
@Slf4j
public class WsMain0 {
    public static void main(String[] args) {
        DubboUtils.initDubboRegistryHost();
        int k = 5;
        System.setProperty("nacos.logging.default.config.enabled", "false");
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
        ConfigurableApplicationContext run = SpringApplication.run(WsMain0.class, args);
        Global.addApplication(run);
    }

    @Bean
    public Server server(){
        return new Server();
    }

    @Bean
    public UserContainer userContainer(){
        return new UserContainerImpl();
    }

    @Bean
    public MessageConvert messageConvert(){
        return new DefaultMessageConvertImpl();
    }

    @Bean
    public MsgSender msgSender(){
        return new KafkaSharedMsgSender();
    }

    @Bean
    @ConditionalOnMissingBean(MsgDataSource.class)
    public MsgDataSource msgDataSource(){
        return MsgDataSource.empty;
    }

    @Bean
    public WsConfig wsConfig(){
        return new WsConfig();
    }
}
